package com.zer0.tga.input;

import java.util.*;

import com.zer0.tga.math.Coordinate;

public class Input {
    public final class SingleInput {
        public boolean nextState = false;
        public boolean wasDown = false;
        public boolean isDown = false;

        public SingleInput() {
        	inputList.add(this);
        }

        public void tick() {
            wasDown = isDown;
            isDown = nextState;
        }

        public boolean wasPressed() {
            return !wasDown && isDown;
        }

        public boolean wasReleased() {
            return wasDown && !isDown;
        }

        public void release() {
            nextState = false;
        }
    }
    
    public int mouseOffset_x;
    public int mouseOffset_y;
    public double scale = 1.0;
    

    private List<SingleInput> inputList = new ArrayList<SingleInput>();

    public SingleInput up 		= 	new SingleInput();
    public SingleInput down 	= 	new SingleInput();
    public SingleInput left 	= 	new SingleInput();
	public SingleInput right 	= 	new SingleInput();
	
    public SingleInput fire 	= 	new SingleInput();
    public SingleInput bomb 	= 	new SingleInput();
    
    public SingleInput enter 	= 	new SingleInput();
    public SingleInput back 	= 	new SingleInput();
    
    
    public Coordinate mousePosition = new Coordinate();
    
    /*public SingleInput map_up 		= 	new SingleInput();
    public SingleInput map_down 	= 	new SingleInput();
    public SingleInput map_right 	= 	new SingleInput();
    public SingleInput map_left 	= 	new SingleInput();
    */

    public void tick() {
        for (SingleInput key : inputList)
            key.tick();
    }

    public void release() {
        for (SingleInput key : inputList)
            key.release();
    }

    public List<SingleInput> getAll() {
        return inputList;
    }
    
    public Coordinate getMouseInGamePosition()
    {
    	Coordinate c = new Coordinate();
    	
    	c.x = (int)((mousePosition.x - mouseOffset_x)/scale);
    	c.y = (int)((mousePosition.y - mouseOffset_y)/scale);
    	
    	return c;
    }
}
